<template>
	<view class="container">
		<com-head textTit="开票历史" :typeVal="1" :scrollTop="scrollTop"></com-head>
		<!-- <u-navbar
			title="开票历史" 
			:customBack="onClickBack" 
		></u-navbar> -->
		
		<template v-if="list.length">
			<view class="lsit" v-for="(ele,index) in list" :key="index">
				<view class="title">{{ele.invoice_date}}</view>
				<view class="contents">
					<view class="list common">
						<text class="t1">电子发票</text>
						<text :class="ele.status == 1 ?  't3' : '' || ele.status == 2 ?  't2' : ''">{{ele.status | status}}</text>
						<!-- <text class="t3" v-if="ele.status == 0">待开票</text>
						<text class="t2" v-if="ele.status == 1">已开票</text>
						<text class="t1" v-if="ele.status == 2">废票</text> -->
					</view>
					<view class="list common border">
						<view class="">
							发票抬头：<text>{{ele.rise_name}}</text>
						</view>
						<text class="price">¥{{ele.money}}</text>
					</view>
					<view class="list" v-if="ele.invoice_code">
						发票代码：<text class="t4" >{{ele.invoice_code}}</text>
					</view>
					<view class="list" v-if="ele.invoice_num">
						发票号码：
						<text class="t4" >{{ele.invoice_num}}</text>
					</view>
				</view>
			</view>
			<u-loadmore margin-top="60" margin-bottom="50" :status="status" />
		</template>
		<view class="noDate" v-else>
			<image src="https://willmid-img.oss-cn-shanghai.aliyuncs.com/2021/09/10/2x-8.png" mode=""></image>
			<view>暂无更多开票历史~</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				status:'loading',
				total:0,
				page:1,
				list:[],
				type:1,
				scrollTop: 0
			}
		},
		onPageScroll(e){
			this.scrollTop = e.scrollTop
		},
		onReachBottom() {
			if (this.total > this.list.length) {
				this.page++;
				this.getInvoieList();
			}
		},
		async onLoad({type}) {
			this.type = type
			this.getInvoieList()
		},
		filters: {
		    status(val) {
		      switch (val) {
		        case 1:
		          val = "待开票";
		          break;
		        case 2:
		          val = "已开票";
		          break;
		        case 3:
		          val = "发票已作废";
		          break;
		        case 20:
		          val = "开票中";
		          break;
		        case 21:
		          val = "开票成功签章中";
		          break;
		        case 22:
		          val = "开票失败";
		          break;
		        case 24:
		          val = "开票成功签章失败";
		          break;
		        case 31:
		          val = "发票作废中";
		          break;
		      }
		      return val;
		    },
		  },
		methods: {
			onClickBack(){
				if(this.type == 1){
					this.utlis.backPage(4)
				}else{
					this.utlis.backPage(1)
				}
			},
			async getInvoieList(){
				let {data,code} = await this.$u.api.getInvoice({page:this.page});
				if(code){
					if(this.page == 1 && !data.data.lenght){
						this.status = 'nomore';
					}
					this.list = [...this.list, ...data.data];
					this.total = data.total;
					if (this.total <= this.list.length) this.status = 'nomore';
					else this.status = 'loading';
				}
			},
		}
	}
</script>

<style lang="scss" scoped >
.container{
	padding: 50rpx 32rpx;
	.noDate{
		width: 360rpx;
		position: absolute;
		left: 50%;
		top: 34%;
		transform: translate(-50%,-50%);
		color: #666666;
		font-size: 26rpx;
		text-align: center;
		image{
			width: 360rpx;
			height: 310rpx;
			display: block;
			margin-bottom: 78rpx;
		}
	}
	.lsit{
		.title{
			font-size: 26rpx;
			font-weight: 500;
			color: #666666;
			line-height: 26rpx;
			padding: 40rpx 32rpx 32rpx 32rpx;
		}
		.contents{
			background-color: #FFFFFF;
			border-radius: 8rpx;
			padding: 43rpx 28rpx 5rpx 28rpx;
			.list{
				color: #999999;
				font-size: 24rpx;
				padding-bottom: 24rpx;
				.t1{
					color: #333333;
					font-size: 28rpx;
				}
				.t2{
					color: #2AB332;
					font-size: 28rpx;
				}
				.t3{
					color: #891F00;
				}
				.t4{
					color: #333333;
					font-size: 28rpx;
				}
			}
			.common{
				display: flex;
				justify-content: space-between;
				padding-bottom: 24rpx;
			}
			.border{
				border-bottom: 1rpx solid rgba(142,142,142,.24);
				margin-bottom: 25rpx;
				color: #666666;
				font-size: 24rpx;
				text{
					color: #333333;
				}
				.price{
					color: #891F00;
					font-size: 28rpx;
				}
			}
		}
	}
	
}
</style>
<style >
page{
	background-color: #F6F7FA;
}
</style>
